package com.koron.standard.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.common.core.config.ThreadLocalContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author jzp
 * @since 2021/7/13 16:04
 */
@Component
@Primary
public class BaseBeanMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        EamUser eamUser = ThreadLocalContext.get();
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "createBy", String.class, eamUser.getAccount());
        this.strictInsertFill(metaObject, "createByName", String.class, eamUser.getName());
        this.strictInsertFill(metaObject, "deptId", String.class, eamUser.getOrgId());
        this.strictInsertFill(metaObject, "deptName", String.class, eamUser.getOrgName());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        EamUser eamUser = ThreadLocalContext.get();
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateBy", String.class,  eamUser.getAccount());
        this.strictUpdateFill(metaObject, "updateByName", String.class, eamUser.getName());
    }

}
